<?
//Import Classes
	require_once('classes/session.php');
	require_once('classes/sql_wtc.php');
	require_once('classes/functions.php');
	require_once('classes/country.php');

	$myDB = new MySQL_class();
	$myDB->Create();

//Get Parameters
	if (!isset($_SESSION['view'])||!$_SESSION['view'][0][0]) {
		@mysql_close();
		header ("Location: empty_cart.php");
		exit();
	}

	if (isset($_SESSION['user'])&&$_SESSION['user'][0])
		$user=$_SESSION['user'];
	else {
		header("Location: sign_in.php");
		exit();
	}

	if (isset($_SESSION['order'])&&$_SESSION['order']['recipient_email']) {
		$oldorder		= $_SESSION['order'];
	}
	else {
		$oldorder						= array();
		$oldorder['recipient_name']		= $user[2].' '.$user[3];
		$oldorder['recipient_email']	= $user[1];
		$oldorder['recipient_address']	= $user[4];
		$oldorder['recipient_country']	= $user[8];
		$oldorder['recipient_zip']		= $user[6];
		$oldorder['recipient_tel1']		= '';
		$oldorder['recipient_tel2']		= '';
		$oldorder['recipient_tel3']		= $user[5];
		$oldorder['billing_address']	= '';
		$oldorder['billing_zip']		= '';
		$oldorder['billing_country']	= $user[8];
		$oldorder['shipping_region']	= 'Hong Kong Island';
		$oldorder['shipping_carrier']	= '';
		if ($user[10]=='Male') $oldorder['recipient_title']='Mr.';
		else $oldorder['recipient_title']='Ms.';
	}

	$order				= array();
	
	if (isset($_POST['act'])&&$_POST['act']=='submit') {
		$order=$_POST;
		$_SESSION['order']	=	$order;
		
		header("Location: check_out_order_details.php");
		
		exit();
	}
	if ($oldorder['billing_address']==$oldorder['recipient_address']&&$oldorder['billing_country']==$oldorder['recipient_country']&&$oldorder['billing_zip']==$oldorder['recipient_zip'])
		$samecheck=' checked';
	else $samecheck='';	

//echo $samecheck;
//Functions	

	$menuhtml		= buildMenu($cat_lev,$category,$cat_par,'product.php');
	$delivery		= buildShippingRegionSelect();

?>

<html>
<head>
<title>Jonesky eShopping</title>
<meta http-equiv="Content-Type" content="="text/ht; charset=big5" >
<link href="css/main.css" rel="stylesheet" type="text/css">

<script language="javascript">
<!--
function copyText(){
	if (document.form1.same.checked) {
		document.form1.billing_address.value=document.form1.recipient_address.value;
		document.form1.billing_zip.value=document.form1.recipient_zip.value;
		document.form1.billing_country.options[document.form1.recipient_country_.selectedIndex].selected=true;
		document.form1.billing_address.readOnly=true;
		document.form1.billing_zip.readOnly=true;
//		document.form1.billing_country.readOnly=true;
//		document.form1.same.value=-1;
	}
	else {
		document.form1.billing_address.value='';
		document.form1.billing_zip.value='';
		document.form1.billing_address.readOnly=false;
		document.form1.billing_zip.readOnly=false;
//		document.form1.billing_country.readOnly=false;
//		document.form1.same.value=1;
	}
}

function update(){
	if (document.form1.same.checked) {
		document.form1.billing_address.value=document.form1.recipient_address.value;
		document.form1.billing_zip.value=document.form1.recipient_zip.value;
		return true;
	}
	else return false;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function getName(variable) {
	var a = new Array();
	var b = new Array();
	a[0]='recipient_name';
	a[1]='recipient_email';
	a[2]='recipient_tel3';
	a[3]='recipient_address';
	a[4]='billing_address';
	b[0]='Recipient Name';
	b[1]='Contact Email';
	b[2]='Telephone';
	b[3]='Registration Address';
	b[4]='Delivery Addres';
	
	for (i=0;i<a.length;i++) {
		if (a[i]==variable) return b[i];
		//alert(a[i]+b[i]);
	}
	return variable;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+getName(nm)+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+getName(nm)+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+getName(nm)+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') {
			if (nm=='recipient_tel3') errors += '- '+'Contact Phone must be filled.'
			else errors += '- '+getName(nm)+' is required.\n'; 
		}}
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}
//-->
</script>

</head>

<body>
<table width="770" align="center" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td height="85" align="center" valign="top">
	  <table width="100%" height="84"  border="0" cellpadding="0" cellspacing="0">
        <tr>
          <td width="205" rowspan="3" align="center" valign="middle" background="images/index_LOGO_t1-1.gif">&nbsp;</td>
          <td width="1" rowspan="3"></td>
          <td height="57" align="right" background="images/index_CH_t1-2-1.gif"><table width="430" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td width="425" height="34" align="right" background="images/index_CH_t1-2-1-2.gif"><a href="../Jonesky_CH/check_out_delivery_details.php"><img src="images/jonesky_chinese.gif" border="0"></a></td>
			  <td width="5"></td>
            </tr>
          </table></td>
        </tr>
        <tr>
          <td height="1"></td>
        </tr>
        <tr>
          <td height="26" align="right" background="images/index_SVC_t1-2-2.gif"><table width="" height="18" border="0" cellpadding="0" cellspacing="0">
            <tr align="left" valign="middle">
              <td width="115"><a class=s3 href="shipping_charge_list.php">- Shipping Charge </a></td>
              <td width="75"><a class=s3 href="view_cart.php">- View Cart </a></td>
              <td width="75"><a class=s3 href="check_out_delivery_details.php">- Check Out</a> </td>
              <td width="155"><a class=s3 href="claim.php">- Redemption Centre Info </a></td>
            </tr>
          </table></td>
        </tr>
      </table></td>
  </tr>
  <tr>
    <td height="111" bgcolor="#FF0000"><img src="images/<?=randomBanner()?>" width="770" height="111"></td>
  </tr>
    <tr>
    <td height="1"></td>
  </tr>
  <tr>
    <td height="475" valign="top"><table width="100%" height="475"  border="0" cellpadding="0" cellspacing="0" class="mytd">
      <tr>
        <td height="31"><table width="100%" height="31"  border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td width="710" background="images/red_navigate.gif"><table width="100%" height="31"  border="0" cellpadding="0" cellspacing="0">
              <tr>
                <td width="43" align="center"><a class=s3 href="index_eng.php">Home</a></td>
                <td width="1"><img src="images/whiteLine.gif"></td>
                <td width="59" align="center"><a class=s3 href="about_us.php">About us </a></td>
                <td width="1"><img src="images/whiteLine.gif"></td>
                <td width="86" align="center"><a class=s3 href="new_products.php">New Products </a></td>
                <td width="1"><img src="images/whiteLine.gif"></td>
                <td width="68" align="center"><a class=s3 href="promotion.php">Promotion</a></td>
                <td width="1"><img src="images/whiteLine.gif"></td>
                <td width="33" align="center"><a class=s3 href="faq.php">FAQ</a></td>
                <td width="1"><img src="images/whiteLine.gif"></td>
                <td width="130" align="center"><a class=s3 href="terms_and_condition.php">Terms and Conditions</a></td>
                <td width="1"><img src="images/whiteLine.gif"></td>
                <td width="83" align="center"><a class=s3 href="return_policy.php">Return Policy </a></td>
                <td width="1"><img src="images/whiteLine.gif"></td>
                <td width="93" align="center"><a class=s3 href="delivery_policy.php">Delivery Policy</a> </td>
                <td width="1"><img src="images/whiteLine.gif"></td>
                <td width="71" align="center"><a class=s3 href="contact_us.php">Contact us </a></td>
                <td width="1"><img src="images/whiteLine.gif"></td>
                <td width="35" align="center"><a class=s3 href="news.php">News</a></td>
              </tr>
            </table></td>
            <td><img src="images/red_navigate_right.gif" width="36" height="31"></td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td height="381"><table width="100%" height="100%"  border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td width="4"></td>
            <td width="192" valign="top">
			<table border="0" cellpadding="0" cellspacing="0">
              <tr>
                <td width="2" bgcolor="#FFFFFF"></td>
                <td width="184" valign="top"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td height="2" bgcolor="#FFFFFF"></td>
                  </tr>
                  <tr>
                    <td height="28"><img src="images/products0.gif" width="184" height="28"></td>
                  </tr>
                  <tr>
                    <td height="2" bgcolor="#FFFFFF"></td>
                  </tr>
                  <tr>
                    <td height="80" background="images/products3.jpg">
                      <form name="searchbox" action="product_search_result.php" method="post"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
                        <tr>
                          <td height="20">&nbsp;&nbsp;&nbsp;&nbsp;<a class=s2>Keywords</a></td>
                        </tr>
                        <tr>
                          <td>&nbsp;&nbsp;&nbsp;<input name="search" type="text" class="text" id="search" size="20"></td>
                        </tr>
                        <tr>
                          <td height="28">&nbsp;&nbsp;&nbsp;<input name="submit" type="submit" class="button" id="submit" onClick="MM_validateForm('search','','R');return document.MM_returnValue" value="Search"></td>
                        </tr>
                      </table></form>
</td>
                  </tr>
				<?=$menuhtml?>
                </table></td>
                <td width="6" valign="top" background="images/index_SVC_t1-2-2.jpg">&nbsp;</td>
              </tr>
              <tr>
                <td width="2" bgcolor="#FFFFFF"></td>
                <td height="12" background="images/Pro_Search_bottom.gif">&nbsp;</td>
                <td width="6"><img src="images/Pro_Search_circle.gif" width="6" height="12"></td>
              </tr>
            </table>
			</td>
            <td width="574" valign="top"><div style="padding:12px 2px;" class="s4">
			<img src="images/procedure3.gif"><br>
              <br>
                    &nbsp;&nbsp;&nbsp;&nbsp;<font size="1">* Optional</font><br>
              <br>
	              <form name="form1" method="post" action="">
	                <table width="520" border="0" align="center" cellpadding="3" cellspacing="0">
                      <tr> 
                        <td colspan="2" class="s10">Recipient Details</td>
                      </tr>
                      <tr> 
                        <td height="10" class="s4"></td>
                        <td height="10" class="s4"></td>
                      </tr>
                      <tr> 
                        <td width="35%" height="20" class="s4">Title:<br></td>
                        <td width="65%" height="25" class="s4"><input name="recipient_title" type="radio" value="Mr." <? if ($oldorder['recipient_title']==''||$oldorder['recipient_title']=='Mr.') echo " checked"; ?>>
                          Mr. 
                          <input type="radio" name="recipient_title" value="Mrs." <? if ($oldorder['recipient_title']=='Mrs.') echo " checked"; ?>>
                          Mrs. 
                          <input type="radio" name="recipient_title" value="Ms." <? if ($oldorder['recipient_title']=='Ms.') echo " checked"; ?>>
                          Ms. </td>
                      </tr>
                      <tr> 
                        <td class="s4">Recipient Name: </td>
                        <td height="25" class="s4"><input name="recipient_name" type="text" id="recipient_name" value="<?=$oldorder['recipient_name']?>" size="35"></td>
                      </tr>
                      <tr> 
                        <td class="s4">Contact Email: </td>
                        <td height="25" class="s4"><input name="recipient_email" type="text" id="recipient_email" value="<?=$oldorder['recipient_email']?>" size="35"></td>
                      </tr>
                      <tr> 
                        <td height="10" class="s4"></td>
                        <td height="10" class="s4"></td>
                      </tr>
                      <tr> 
                        <td colspan="2" class="s10">Delivery Method</td>
                      </tr>
                      <tr>
                        <td height="10" class="s4"></td>
                        <td height="10" class="s4"></td>
                      </tr>
					<?=$delivery?>
                      <tr> 
                        <td height="10"></td>
                        <td height="10"></td>
                      </tr>
                      <tr> 
                        <td colspan="2" class="s10">Member Registration Address</td>
                      </tr>
                      <tr> 
                        <td height="10" class="s4"></td>
                        <td height="10"></td>
                      </tr>
                      <tr> 
                        <td valign="top" class="s4">*Registration address:</td>
                        <td>
						<textarea name="recipient_address" cols="40" rows="4" class="s4" id="recipient_address"  onChange="update()" onKeyDown="update()" onKeyUp="update()" onKeyPress="update()"><?=$oldorder['recipient_address']?></textarea></td>
                      </tr>
                      <tr class="s4"> 
                        <td class="s4">Country:</td>
                        <td><input type="hidden" name="recipient_country" value="<?=$oldorder['recipient_country']?>">
						<? FFPCountry($oldorder['recipient_country'],'recipient_country_','disabled onChange="if (document.form1.same.checked) document.form1.billing_country.options[document.form1.recipient_country.selectedIndex].selected=true;"');?></td>
                      </tr>
                      <tr class="s4"> 
                        <td class="s4">Zip Code:</td>
                        <td><input name="recipient_zip" type="text" id="recipient_zip" value="<?=$oldorder['recipient_zip']?>" size="5"  onChange="update()" onKeyDown="update()" onKeyUp="update()" onKeyPress="update()"></td>
                      </tr>
                      <tr class="s4"> 
                        <td class="s4">Contact Phone:</td>
                        <td><input name="recipient_tel1" type="text" id="recipient_tel1" size="5" value="<?=$oldorder['recipient_tel1']?>">
                          (*country code) </td>
                      </tr>
                      <tr class="s4"> 
                        <td>&nbsp;</td>
                        <td><input name="recipient_tel2" type="text" id="recipient_tel2" size="5" value="<?=$oldorder['recipient_tel2']?>">
                          (*area code)</td>
                      </tr>
                      <tr class="s4"> 
                        <td>&nbsp;</td>
                        <td><input name="recipient_tel3" type="text" id="recipient_tel3" value="<?=$oldorder['recipient_tel3']?>">
                          (telephone) </td>
                      </tr>
                      <tr class="s4"> 
                        <td height="10"></td>
                        <td height="10"></td>
                      </tr>
					  <tbody id="tbody_delivery_addr">
                      <tr class="s4"> 
                        <td colspan="2" class="s10">Delivery Address / Redemption Centre Address</td>
                      </tr>
                      <tr class="s4"> 
                        <td height="10" class="s4"></td>
                        <td height="10"></td>
                      </tr>
                      <tr class="s4" id="un_claim_addr_box">
                        <td class="s4" colspan=2>Same as member registration address :<input name="same" type="checkbox" id="same" value="1" onClick="copyText();if(this.checked==true) { document.form1.claim_addr.checked=false;ifclaim_1.style.display='';ifclaim_2.style.display='';ifclaim_3.style.display=''; }" <?=$samecheck?>></td>
                      </tr>
                      <tr class="s4" id="claim_addr_box" style="display:none">
                        <td class="s4" colspan=2>Redemption Centre Address :<input name="claim_addr" type="checkbox" id="claim_addr" value="1" onClick="if(this.checked==true) { document.form1.same.checked=false;document.form1.billing_address.value='';ifclaim_1.style.display='none';ifclaim_2.style.display='none';ifclaim_3.style.display='none'; } else { ifclaim_1.style.display='';ifclaim_2.style.display='';ifclaim_3.style.display=''; }"></td>
                      </tr>

                      <tr class="s4" id="ifclaim_1"> 
                        <td valign="top" class="s4">*Delivery address:</td>
                        <td><textarea name="billing_address" cols="40" rows="4" id="billing_address"><?=$oldorder['billing_address']?></textarea></td>
                      </tr>
                      <tr class="s4" id="ifclaim_2"> 
                        <td class="s4">Country:</td>
                        <td><? FFPCountry($oldorder['billing_country'],'billing_country','onChange="if (document.form1.same.checked) document.form1.billing_country.options[document.form1.recipient_country_.selectedIndex].selected=true;"');?></td>
                      </tr>
                      <tr class="s4"  id="ifclaim_3"> 
                        <td class="s4">Zip Code:</td>
                        <td><input name="billing_zip" type="text" id="billing_zip" size="5" value="<?=$oldorder['billing_zip']?>"></td>
                      </tr>

                      <tr class="s4"> 
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                      </tr>
					  </tbody>
                      <tr> 
                        <td>&nbsp;</td>
                        <td><input name="act" type="hidden" id="act" value="submit"></td>
                      </tr>
                      <tr> 
                        <td><div align="right"><a href="<?=$PHP_SELF?>"><img src="images/clear_up.gif" border="0"></a></div></td>
                        <td>  <input name="submit2" type="image" id="submit2" onClick="if(shipping_carrier.options[shipping_carrier.options.selectedIndex].value == 'Self Take'){MM_validateForm('recipient_name','','R','recipient_email','','RisEmail','recipient_tel3','','R','recipient_address','','R');return document.MM_returnValue;} else if (claim_addr.checked==false) {  MM_validateForm('recipient_name','','R','recipient_email','','RisEmail','recipient_tel3','','R','recipient_address','','R','billing_address','','R');return document.MM_returnValue;}" src="images/ptop_up.gif" border="0"></td>
                      </tr>
                    </table> 
				</form>
            </div>
    </td>
          </tr>
        </table></td>
      </tr> 
	  
      <tr>
          <td height="80" align="center" valign="bottom" bgcolor="#FFFFFF"><span class="s1">Copyright 
            &copy; 2004, All Rights Reserved by Jonesky Limited. <br>
            &nbsp;&nbsp; </span></td>
      </tr>

    </table></td>
  </tr>

</table>
</body>
</html>
<?
@mysql_close();
?>